{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'refresh_token': '25.715868eb7dde1c9ef73f0423eff5e267.315360000.1926765653.282335-23575562', 'expires_in': 2592000, 'session_key': '9mzdXRXw2tNbdTGJayiBpNKehTLtwF99RbH1LSBZvavGbx3aRxh00Ht6jsIw9YQ6Jh0BcLJwOFSAohSvR5OVrsW9vMnKrA==', 'access_token': '24.fad2c94a080de805f184e2c2e6e45315.2592000.1613997653.282335-23575562', 'scope': 'public vis-classify_dishes vis-classify_car brain_all_scope vis-classify_animal vis-classify_plant brain_object_detect brain_realtime_logo brain_dish_detect brain_car_detect brain_animal_classify brain_plant_classify brain_ingredient brain_advanced_general_classify brain_custom_dish brain_poi_recognize brain_vehicle_detect brain_redwine brain_currency brain_vehicle_damage wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理 smartapp_component smartapp_search_plugin', 'session_secret': '75ca644a91d9cfef721912a1795eaef4'}\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>refresh_token</th>\n",
       "      <td>25.715868eb7dde1c9ef73f0423eff5e267.315360000....</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>expires_in</th>\n",
       "      <td>2592000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>session_key</th>\n",
       "      <td>9mzdXRXw2tNbdTGJayiBpNKehTLtwF99RbH1LSBZvavGbx...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>access_token</th>\n",
       "      <td>24.fad2c94a080de805f184e2c2e6e45315.2592000.16...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>scope</th>\n",
       "      <td>public vis-classify_dishes vis-classify_car br...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>session_secret</th>\n",
       "      <td>75ca644a91d9cfef721912a1795eaef4</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                                0\n",
       "refresh_token   25.715868eb7dde1c9ef73f0423eff5e267.315360000....\n",
       "expires_in                                                2592000\n",
       "session_key     9mzdXRXw2tNbdTGJayiBpNKehTLtwF99RbH1LSBZvavGbx...\n",
       "access_token    24.fad2c94a080de805f184e2c2e6e45315.2592000.16...\n",
       "scope           public vis-classify_dishes vis-classify_car br...\n",
       "session_secret                   75ca644a91d9cfef721912a1795eaef4"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "import requests \n",
    "import pandas as pd\n",
    "import json\n",
    "\n",
    "# client_id 为官网获取的AK， client_secret 为官网获取的SK\n",
    "host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=WmoAqK4R5PiyTTBe37SYCLzA&client_secret=h7rcG9Gu5sT6rCLZjzVxImc1IL2wumGR'\n",
    "response = requests.get(host)\n",
    "if response:\n",
    "    print(response.json())\n",
    "pd.json_normalize(response.json()).T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'24.fad2c94a080de805f184e2c2e6e45315.2592000.1613997653.282335-23575562'"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "access_token = response.json()[\"access_token\"]\n",
    "access_token"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'log_id': 7415716162066036631, 'result_num': 5, 'result': [{'score': 0.49419689178466797, 'name': '黑樱桃'}, {'score': 0.1938685178756714, 'name': '樱桃'}, {'score': 0.12318649888038635, 'name': '大樱桃'}, {'score': 0.09199383854866028, 'name': '黑珍珠樱桃'}, {'score': 0.059966035187244415, 'name': '车厘子'}]}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "细粒度图像识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/image-classify/v1/classify/ingredient\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('C:/Users/bao/Desktop/images/cherry.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\"image\":img}\n",
    "access_token = '24.3fe0726d5b07ebb1ca18af76469617fd.2592000.1613995854.282335-23580934'\n",
    "request_url = request_url + \"?access_token=\" + access_token\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "if response:\n",
    "    print (response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "b'{\"RequestId\":\"e3247878-26f1-4d46-9da6-e9c286db1144\",\"errorCode\":\"3008\",\"l\":\"zh-CHS2en\"}'\n"
     ]
    }
   ],
   "source": [
    "# -*- coding: utf-8 -*-\n",
    "import sys\n",
    "import uuid\n",
    "import requests\n",
    "import wave\n",
    "import base64\n",
    "import hashlib\n",
    "\n",
    "from imp import reload\n",
    "\n",
    "\n",
    "reload(sys)\n",
    "\n",
    "YOUDAO_URL = 'https://openapi.youdao.com/speechtransapi'\n",
    "APP_KEY = '4ae8cc4d4e76466a'\n",
    "APP_SECRET = 'OA2Xb4UKOZmkHSGnd71S7tPr2J78FEtA'\n",
    "\n",
    "def truncate(q):\n",
    "    if q is None:\n",
    "        return None\n",
    "    size = len(q)\n",
    "    return q if size <= 20 else q[0:10] + str(size) + q[size-10:size]\n",
    "\n",
    "def encrypt(signStr):\n",
    "    hash_algorithm = hashlib.md5()\n",
    "    hash_algorithm.update(signStr.encode('utf-8'))\n",
    "    return hash_algorithm.hexdigest()\n",
    "\n",
    "def do_request(data):\n",
    "    headers = {'Content-Type': 'application/x-www-form-urlencoded'}\n",
    "    return requests.post(YOUDAO_URL, data=data, headers=headers)\n",
    "\n",
    "def connect():\n",
    "    audio_file_path = 'C:/Users/bao/Desktop/translate5.wav'\n",
    "    lang_type = '合成文本的语言类型'\n",
    "    extension = audio_file_path[audio_file_path.rindex('.')+1:]\n",
    "    if extension != 'wav':\n",
    "        print('不支持的音频类型')\n",
    "        sys.exit(1)\n",
    "    wav_info = wave.open(audio_file_path, 'rb')\n",
    "    sample_rate = wav_info.getframerate()\n",
    "    nchannels = wav_info.getnchannels()\n",
    "    wav_info.close()\n",
    "    with open(audio_file_path, 'rb') as file_wav:\n",
    "        q = base64.b64encode(file_wav.read()).decode('utf-8')\n",
    "\n",
    "    data = {}\n",
    "    data['from'] = 'zh-CHS'\n",
    "    data['to'] = 'en'\n",
    "    salt = str(uuid.uuid1())\n",
    "    signStr = APP_KEY + q + salt + APP_SECRET\n",
    "    sign = encrypt(signStr)\n",
    "    data['appKey'] = APP_KEY\n",
    "    data['q'] = q\n",
    "    data['salt'] = salt\n",
    "    data['sign'] = sign\n",
    "    data['signType'] = \"v1\"\n",
    "    data['langType'] = lang_type\n",
    "    data['rate'] = sample_rate\n",
    "    data['format'] = 'wav'\n",
    "    data['channel'] = nchannels\n",
    "    data['type'] = 1\n",
    "\n",
    "    response = do_request(data)\n",
    "    print(response.content)\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    connect()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "fetch token begin\n",
      "{\"access_token\":\"24.f44bd6d64d5d934f097c70a4ef1111ea.2592000.1613998074.282335-23580550\",\"session_key\":\"9mzdXUDwjCVPSA5ADulfa6iznYH0lAuWY9ngKHShZwmeFtDrcTECMgUmqO5RqcHOvNY+yIzaEpTmdTa656PvS3tukXM4YA==\",\"scope\":\"audio_voice_assistant_get brain_enhanced_asr audio_tts_post brain_speech_realtime public brain_all_scope picchain_test_picchain_api_scope brain_asr_async wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test\\u6743\\u9650 vis-classify_flower lpq_\\u5f00\\u653e cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_\\u5f00\\u653eScope vis-ocr_\\u865a\\u62df\\u4eba\\u7269\\u52a9\\u7406 idl-video_\\u865a\\u62df\\u4eba\\u7269\\u52a9\\u7406 smartapp_component smartapp_search_plugin\",\"refresh_token\":\"25.222f46e0c0d28a520555431d3a7bbe00.315360000.1926766074.282335-23580550\",\"session_secret\":\"34c86201ed1abe8cf6e3043e84533d75\",\"expires_in\":2592000}\n",
      "\n",
      "{'access_token': '24.f44bd6d64d5d934f097c70a4ef1111ea.2592000.1613998074.282335-23580550', 'session_key': '9mzdXUDwjCVPSA5ADulfa6iznYH0lAuWY9ngKHShZwmeFtDrcTECMgUmqO5RqcHOvNY+yIzaEpTmdTa656PvS3tukXM4YA==', 'scope': 'audio_voice_assistant_get brain_enhanced_asr audio_tts_post brain_speech_realtime public brain_all_scope picchain_test_picchain_api_scope brain_asr_async wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理 smartapp_component smartapp_search_plugin', 'refresh_token': '25.222f46e0c0d28a520555431d3a7bbe00.315360000.1926766074.282335-23580550', 'session_secret': '34c86201ed1abe8cf6e3043e84533d75', 'expires_in': 2592000}\n",
      "SUCCESS WITH TOKEN: 24.f44bd6d64d5d934f097c70a4ef1111ea.2592000.1613998074.282335-23580550 ; EXPIRES IN SECONDS: 2592000\n",
      "%E5%B0%8F%E8%80%81%E9%BC%A0%E8%8E%AB%E9%87%8C%E5%92%8C%E4%BB%96%E7%9A%84%E5%AE%B6%E4%BA%BA%E4%BD%8F%E5%9C%A8%E6%9E%9C%E5%9B%AD%E9%87%8C%EF%BC%8C%E7%A7%8B%E5%A4%A9%E6%98%AF%E4%BB%96%E4%BB%AC%E6%9C%80%E5%BF%AB%E4%B9%90%E7%9A%84%E6%97%A5%E5%AD%90%E3%80%82%E6%98%9F%E6%9C%9F%E4%B8%80%EF%BC%8C%E9%BC%A0%E5%A6%88%E5%A6%88%E4%B8%8A%E8%A1%97%E5%8E%BB%E4%B9%B0%E8%8F%9C%EF%BC%8C%E7%AA%81%E7%84%B6%E5%8F%91%E7%8E%B0%E8%8B%B9%E6%9E%9C%E6%A0%91%E4%B8%8B%E6%9C%89%E5%87%A0%E4%B8%AA%E7%BA%A2%E7%BA%A2%E7%9A%84%E5%A4%A7%E8%8B%B9%E6%9E%9C%E3%80%82%E2%80%9C%E5%95%8A%EF%BC%8C%E7%9C%9F%E6%98%AF%E5%A4%AA%E5%B9%B8%E8%BF%90%E4%BA%86%E3%80%82%E2%80%9D%E9%BC%A0%E5%A6%88%E5%A6%88%E8%AF%B4%E3%80%82%E9%BC%A0%E5%A6%88%E5%A6%88%E5%9B%9E%E5%88%B0%E5%AE%B6%EF%BC%8C%E6%8A%8A%E4%B8%80%E4%B8%AA%E5%A4%A7%E8%8B%B9%E6%9E%9C%E9%80%81%E7%BB%99%E8%8E%AB%E9%87%8C%EF%BC%8C%E5%89%A9%E4%B8%8B%E7%9A%84%E5%A4%A7%E8%8B%B9%E6%9E%9C%E5%81%9A%E6%88%90%E4%BA%86%E8%8B%B9%E6%9E%9C%E9%A6%85%E9%A5%BC%E3%80%82\n",
      "test on Web Browserhttp://tsn.baidu.com/text2audio?tok=24.f44bd6d64d5d934f097c70a4ef1111ea.2592000.1613998074.282335-23580550&tex=%25E5%25B0%258F%25E8%2580%2581%25E9%25BC%25A0%25E8%258E%25AB%25E9%2587%258C%25E5%2592%258C%25E4%25BB%2596%25E7%259A%2584%25E5%25AE%25B6%25E4%25BA%25BA%25E4%25BD%258F%25E5%259C%25A8%25E6%259E%259C%25E5%259B%25AD%25E9%2587%258C%25EF%25BC%258C%25E7%25A7%258B%25E5%25A4%25A9%25E6%2598%25AF%25E4%25BB%2596%25E4%25BB%25AC%25E6%259C%2580%25E5%25BF%25AB%25E4%25B9%2590%25E7%259A%2584%25E6%2597%25A5%25E5%25AD%2590%25E3%2580%2582%25E6%2598%259F%25E6%259C%259F%25E4%25B8%2580%25EF%25BC%258C%25E9%25BC%25A0%25E5%25A6%2588%25E5%25A6%2588%25E4%25B8%258A%25E8%25A1%2597%25E5%258E%25BB%25E4%25B9%25B0%25E8%258F%259C%25EF%25BC%258C%25E7%25AA%2581%25E7%2584%25B6%25E5%258F%2591%25E7%258E%25B0%25E8%258B%25B9%25E6%259E%259C%25E6%25A0%2591%25E4%25B8%258B%25E6%259C%2589%25E5%2587%25A0%25E4%25B8%25AA%25E7%25BA%25A2%25E7%25BA%25A2%25E7%259A%2584%25E5%25A4%25A7%25E8%258B%25B9%25E6%259E%259C%25E3%2580%2582%25E2%2580%259C%25E5%2595%258A%25EF%25BC%258C%25E7%259C%259F%25E6%2598%25AF%25E5%25A4%25AA%25E5%25B9%25B8%25E8%25BF%2590%25E4%25BA%2586%25E3%2580%2582%25E2%2580%259D%25E9%25BC%25A0%25E5%25A6%2588%25E5%25A6%2588%25E8%25AF%25B4%25E3%2580%2582%25E9%25BC%25A0%25E5%25A6%2588%25E5%25A6%2588%25E5%259B%259E%25E5%2588%25B0%25E5%25AE%25B6%25EF%25BC%258C%25E6%258A%258A%25E4%25B8%2580%25E4%25B8%25AA%25E5%25A4%25A7%25E8%258B%25B9%25E6%259E%259C%25E9%2580%2581%25E7%25BB%2599%25E8%258E%25AB%25E9%2587%258C%25EF%25BC%258C%25E5%2589%25A9%25E4%25B8%258B%25E7%259A%2584%25E5%25A4%25A7%25E8%258B%25B9%25E6%259E%259C%25E5%2581%259A%25E6%2588%2590%25E4%25BA%2586%25E8%258B%25B9%25E6%259E%259C%25E9%25A6%2585%25E9%25A5%25BC%25E3%2580%2582&per=4&spd=5&pit=5&vol=5&aue=3&cuid=123456PYTHON&lan=zh&ctp=1\n",
      "tts api  error:{\"err_detail\":\"4: Open api request limit reached\",\"err_msg\":\"4: Open api request limit reached\",\"err_no\":502,\"err_subcode\":4,\"tts_logid\":227647416}\n",
      "\n",
      "result saved as :error.txt\n"
     ]
    }
   ],
   "source": [
    "# coding=utf-8\n",
    "import sys\n",
    "import json\n",
    "\n",
    "IS_PY3 = sys.version_info.major == 3\n",
    "if IS_PY3:\n",
    "    from urllib.request import urlopen\n",
    "    from urllib.request import Request\n",
    "    from urllib.error import URLError\n",
    "    from urllib.parse import urlencode\n",
    "    from urllib.parse import quote_plus\n",
    "else:\n",
    "    import urllib2\n",
    "    from urllib import quote_plus\n",
    "    from urllib2 import urlopen\n",
    "    from urllib2 import Request\n",
    "    from urllib2 import URLError\n",
    "    from urllib import urlencode\n",
    "\n",
    "API_KEY = 'zseyH3GzGQhtljPL9UqV05SY'\n",
    "SECRET_KEY = 'tqpFxim1LcgPhuShtwgRZBLfEixjhHtd'\n",
    "\n",
    "TEXT = \"小老鼠莫里和他的家人住在果园里，秋天是他们最快乐的日子。星期一，鼠妈妈上街去买菜，突然发现苹果树下有几个红红的大苹果。“啊，真是太幸运了。”鼠妈妈说。鼠妈妈回到家，把一个大苹果送给莫里，剩下的大苹果做成了苹果馅饼。\"\n",
    "\n",
    "# 发音人选择, 0为普通女声，1为普通男生，3为情感合成-度逍遥，4为情感合成-度丫丫，默认为普通女声\n",
    "PER = 4\n",
    "# 语速，取值0-15，默认为5中语速\n",
    "SPD = 5\n",
    "# 音调，取值0-15，默认为5中语调\n",
    "PIT = 5\n",
    "# 音量，取值0-9，默认为5中音量\n",
    "VOL = 5\n",
    "# 下载的文件格式, 3：mp3(default) 4： pcm-16k 5： pcm-8k 6. wav\n",
    "AUE = 3\n",
    "\n",
    "FORMATS = {3: \"mp3\", 4: \"pcm\", 5: \"pcm\", 6: \"wav\"}\n",
    "FORMAT = FORMATS[AUE]\n",
    "\n",
    "CUID = \"123456PYTHON\"\n",
    "\n",
    "TTS_URL = 'http://tsn.baidu.com/text2audio'\n",
    "\n",
    "\n",
    "class DemoError(Exception):\n",
    "    pass\n",
    "\n",
    "\n",
    "\"\"\"  TOKEN start \"\"\"\n",
    "\n",
    "TOKEN_URL = 'http://openapi.baidu.com/oauth/2.0/token'\n",
    "SCOPE = 'audio_tts_post'  # 有此scope表示有tts能力，没有请在网页里勾选\n",
    "\n",
    "\n",
    "def fetch_token():\n",
    "    print(\"fetch token begin\")\n",
    "    params = {'grant_type': 'client_credentials',\n",
    "              'client_id': API_KEY,\n",
    "              'client_secret': SECRET_KEY}\n",
    "    post_data = urlencode(params)\n",
    "    if (IS_PY3):\n",
    "        post_data = post_data.encode('utf-8')\n",
    "    req = Request(TOKEN_URL, post_data)\n",
    "    try:\n",
    "        f = urlopen(req, timeout=5)\n",
    "        result_str = f.read()\n",
    "    except URLError as err:\n",
    "        print('token http response http code : ' + str(err.code))\n",
    "        result_str = err.read()\n",
    "    if (IS_PY3):\n",
    "        result_str = result_str.decode()\n",
    "\n",
    "    print(result_str)\n",
    "    result = json.loads(result_str)\n",
    "    print(result)\n",
    "    if ('access_token' in result.keys() and 'scope' in result.keys()):\n",
    "        if not SCOPE in result['scope'].split(' '):\n",
    "            raise DemoError('scope is not correct')\n",
    "        print('SUCCESS WITH TOKEN: %s ; EXPIRES IN SECONDS: %s' % (result['access_token'], result['expires_in']))\n",
    "        return result['access_token']\n",
    "    else:\n",
    "        raise DemoError('MAYBE API_KEY or SECRET_KEY not correct: access_token or scope not found in token response')\n",
    "\n",
    "\n",
    "\"\"\"  TOKEN end \"\"\"\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    token = fetch_token()\n",
    "    tex = quote_plus(TEXT)  # 此处TEXT需要两次urlencode\n",
    "    print(tex)\n",
    "    params = {'tok': token, 'tex': tex, 'per': PER, 'spd': SPD, 'pit': PIT, 'vol': VOL, 'aue': AUE, 'cuid': CUID,\n",
    "              'lan': 'zh', 'ctp': 1}  # lan ctp 固定参数\n",
    "\n",
    "    data = urlencode(params)\n",
    "    print('test on Web Browser' + TTS_URL + '?' + data)\n",
    "\n",
    "    req = Request(TTS_URL, data.encode('utf-8'))\n",
    "    has_error = False\n",
    "    try:\n",
    "        f = urlopen(req)\n",
    "        result_str = f.read()\n",
    "\n",
    "        headers = dict((name.lower(), value) for name, value in f.headers.items())\n",
    "\n",
    "        has_error = ('content-type' not in headers.keys() or headers['content-type'].find('audio/') < 0)\n",
    "    except  URLError as err:\n",
    "        print('asr http response http code : ' + str(err.code))\n",
    "        result_str = err.read()\n",
    "        has_error = True\n",
    "\n",
    "    save_file = \"error.txt\" if has_error else 'result.' + FORMAT\n",
    "    with open(save_file, 'wb') as of:\n",
    "        of.write(result_str)\n",
    "\n",
    "    if has_error:\n",
    "        if (IS_PY3):\n",
    "            result_str = str(result_str, 'utf-8')\n",
    "        print(\"tts api  error:\" + result_str)\n",
    "\n",
    "    print(\"result saved as :\" + save_file)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
